use core::fmt::Debug;

#[repr(C)]
#[derive(Default, Debug)]
pub struct Ident {
    pub magic: [u8; 4],
    pub file_class: FileClass,
    pub data_encode: DataEncode,
    pub file_version: u8,
    pub osabi: Osabi,
    pub abi_version: u8,
}

impl Ident {
    pub const MAGIC: [u8; 4] = [0x7f, 'E' as u8, 'L' as u8, 'F' as u8];
}

impl_borrow!(Ident);

trans! {
    #[derive(Default, Debug)]
    DataEncode: u8,
    #[derive(Default)]
    FileClass:u8,
    #[derive(Default, Debug)]
    Osabi:u8
}
impl Debug for FileClass {
    fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
        if *self == FileClass::ELFCLASS64 {
            return f.write_str("ELFCLASS64");
        }
        if *self == FileClass::ELFCLASS32 {
            return f.write_str("ELFCLASS32");
        }
        return f.write_fmt(format_args!("Unknown class {}", self.data));
    }
}
def_const! {
    FileClass {
        ELFCLASS32: 1,
        ELFCLASS64: 2
    }
    DataEncode {
        LSB: 1,
        MSB: 2
    }
    Osabi {
        /// System V ABI
        SYSV: 0,
        /// HP-UX 操作系统
        HPUX: 1,
        /// 独立的嵌入式应用（无操作系统）
        STANDLONE: 255
    }
}
